<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="display-el" %>
<%@ taglib uri="ford-arg/tags" prefix="ft" %>

<SCRIPT language="JavaScript" 
        src="scripts/CalendarPopup.js">
</SCRIPT>  
<script language="JavaScript" src="scripts/popups.js"></script>
<script type="text/javascript" language="javascript"
	src="scripts/ajaxSearch.js">
</script>


<script language="javascript">
	var cal = new CalendarPopup(); 
	cal.showNavigationDropdowns();
	cal.setMonthNames('<bean:message key="label.month.january"/>',
						'<bean:message key="label.month.february"/>',
						'<bean:message key="label.month.march"/>',
						'<bean:message key="label.month.april"/>',
						'<bean:message key="label.month.may"/>',
						'<bean:message key="label.month.june"/>',
						'<bean:message key="label.month.july"/>',
						'<bean:message key="label.month.august"/>',
						'<bean:message key="label.month.september"/>',
						'<bean:message key="label.month.october"/>',
						'<bean:message key="label.month.november"/>',
						'<bean:message key="label.month.december"/>');
	cal.setDayHeaders('<bean:message key="label.day.sunday.capital"/>',
						'<bean:message key="label.day.monday.capital"/>',
						'<bean:message key="label.day.tuesday.capital"/>',
						'<bean:message key="label.day.wednesday.capital"/>',
						'<bean:message key="label.day.thursday.capital"/>',
						'<bean:message key="label.day.friday.capital"/>',
						'<bean:message key="label.day.saturday.capital"/>');
	cal.setTodayText('<bean:message key="label.today"/>');

	function enableDiv(id, status, clear) {
		var hijos = document.getElementById(id).childNodes;
		for (var i = 0; i < hijos.length; i++) {
			if (hijos[i].tagName=="SELECT" || hijos[i].tagName=="INPUT") {
				hijos[i].disabled = !status;
				if(clear){
					if (hijos[i].tagName=="SELECT") {
						hijos[i].selectedIndex = 0;
					} else if (hijos[i].tagName=="INPUT" && hijos[i].type=="text") {
						hijos[i].value="";
					}
				}
			}
		};		
	}
	
	function enableAllParts(){
		enableDiv('partDiv',false,true);
		enableDiv('commodityDiv',false,true);
	}
	
	function enableCommodity(){
		enableDiv('partDiv',false,true);
		enableDiv('commodityDiv',true,true);
	}
	
	function enablePart(){
		enableDiv('partDiv',true,true);
		enableDiv('commodityDiv',false,true);
	}
	
	function enablePercent(){
		enableDiv('newPriceDiv',false,true);
		enableDiv('percentDiv',true,true);
	}
	
	function enableNewPrice(){
		enableDiv('newPriceDiv',true,true);
		enableDiv('percentDiv',false,true);
	}
	
	function editItem(rowNum) {
		document.AgreementDetailForm.action = "AgreementDetailActionEdit.do";
		document.AgreementDetailForm.section.value = "edit";
		document.AgreementDetailForm.editBlocked.value = "true";
		document.AgreementDetailForm.selectedIndex.value = rowNum;
	}
	
	function deleteItem(rowNum){
		if(confirm('<bean:message key="requestItem.confirmDelete" />')){
			document.AgreementDetailForm.action = "AgreementDetailActionDelete.do";
			document.AgreementDetailForm.section.value = "delete";
			document.AgreementDetailForm.editBlocked.value = "false";
			document.AgreementDetailForm.selectedIndex.value = rowNum;
			document.AgreementDetailForm.submit();
		}else{
			return false;
		}
	}
	
	function createUpdateitem() {
		document.AgreementDetailForm.action = "AgreementDetailActionCreateUpdate.do";
		document.AgreementDetailForm.section.value = "createUpdate";
		document.AgreementDetailForm.submit();
	}
	
	function saveComments(){
		document.AgreementDetailForm.action = "AgreementDetailActionSaveComments.do";
		document.AgreementDetailForm.section.value = "saveComments";
		document.AgreementDetailForm.submit();
	}
	
	function cleanCreateFields(){
		document.AgreementDetailForm.action = "AgreementDetailActionCleanCreateFields.do";
		document.AgreementDetailForm.section.value = "saveComments";
		document.AgreementDetailForm.submit();
	}
	
	
</script>

<logic:equal name="AgreementDetailForm" property="section" value="edit">
	<bean:define id="disableScope">true</bean:define>
</logic:equal>
<logic:notEqual name="AgreementDetailForm" property="section" value="edit">
	<bean:define id="disableScope">false</bean:define>
</logic:notEqual>
	
<table>
	<tr>
		<td colspan="2"><h2><bean:message key="agreementDetail.title"/></h2></td>
	</tr>
</table>
<br/>
<html:form action="/AgreementDetailActionInit">
<html:hidden property="section" />
<html:hidden property="editBlocked"/>
<html:hidden property="selectedIndex"/>
<html:hidden styleId="supplierClassH" property="agreement.teess01Supplier.eess01SupplierClassCodeC"/>
<html:hidden styleId="supplierCodeH" property="agreement.teess01Supplier.eess01SupplierCodeC"/>

	<%-- Mantiene el numero de pagina despues del submit --%>
	<ft:saveActivePageNumber/>
	
	<bean:define id="itemTitle">
		<bean:message key="agreementDetail.label.tableHeader.item" />
	</bean:define>
	<bean:define id="vehicleLineTitle">
		<bean:message key="agreementDetail.label.tableHeader.vehicleLine" />
	</bean:define>
	<bean:define id="typeTitle">
		<bean:message key="agreementDetail.label.tableHeader.type" />
	</bean:define>
	<bean:define id="descriptionTitle">
		<bean:message key="agreementDetail.label.tableHeader.description" />
	</bean:define>
	<bean:define id="increaseTitle">
		<bean:message key="agreementDetail.label.tableHeader.percentIncrease" />
	</bean:define>
	<bean:define id="priceTitle">
		<bean:message key="agreementDetail.label.tableHeader.price" />
	</bean:define>
	<bean:define id="fullEconomicTitle">
		<bean:message key="agreementDetail.label.tableHeader.fullEconomic" />
	</bean:define>
	<bean:define id="payPolTitle">
		<bean:message key="agreementDetail.label.tableHeader.payPol" />
	</bean:define>
	<bean:define id="effDateTitle">
		<bean:message key="agreementDetail.label.tableHeader.effDate" />
	</bean:define>
	<bean:define id="registerTitle">
		<bean:message key="agreementDetail.label.tableHeader.registered" />
	</bean:define>
	<bean:define id="actionsTitle">
		<bean:message key="part.label.tableHeader.actions" />
	</bean:define>
	<bean:define id="edit">
		<bean:message key="label.update" />
	</bean:define>
	<bean:define id="delete">
		<bean:message key="label.delete" />
	</bean:define>
	
	<table style="width: 800px;" class="no_border">
		<tr>
			<td class="text_blue_bold align_left" width="14%">
				<bean:message key="supplier.label.supplier" />:
			</td>
			<td class="align_left" width="30%">
				<bean:write name="AgreementDetailForm" property="agreement.teess01Supplier.eess01SupplierCodeC"/>&nbsp;&nbsp;&nbsp;&nbsp;
				<bean:write name="AgreementDetailForm" property="agreement.teess01Supplier.eess01SupplierNameN"/>
			</td>
			<td class="text_blue_bold align_left" width="16%">
				<bean:message key="agreementDetail.label.economicLevel" />:
			</td>
			<td class="align_left" width="14%">
				<bean:write name="AgreementDetailForm" property="agreement.eesr03AgreeEcolevelDateY" formatKey="format.date"/>
			</td>
			<td class="text_blue_bold align_left" width="11%">
				<bean:message key="agreementDetail.label.effective" />:
			</td>
			<td class="align_left" width="15%">
				<bean:write name="AgreementDetailForm" property="agreement.eesr03AgreeEffectiveDateY" formatKey="format.date"/>
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="agreementDetail.label.description" />:
			</td>
			<td class="align_left">
				<bean:write name="AgreementDetailForm" property="agreement.eesr03AgreeDescriptionX" />
			</td>
			<td class="text_blue_bold align_left">
				<bean:message key="agreementDetail.label.issued" />:
			</td>
			<td class="align_left">
				<bean:write name="AgreementDetailForm" property="agreement.eesr03AgreeIssueDateY" formatKey="format.date"/>
			</td>
			<td class="text_blue_bold align_left">
				<bean:message key="agreementDetail.label.signedOff" />:
			</td>
			<td class="align_left">
				<bean:write name="AgreementDetailForm" property="agreement.eesr03AgreeSignatureDateY" formatKey="format.date"/>
			</td>
		</tr>
	</table>
	<br/>
	
	<div class="edit_out align_center" style="width:800px;" >
	<div class="edit align_center" style="width: 800px;" >
		<table style="width: 800px;" class="no_border">
			<tr>
				<td class="text_blue_bold align_left">
					<table style="width: 700px;">
						<tr>
							<td class="text_blue_bold align_left" colspan="7">
								<h2><bean:message key="costStructure.item"/></h2>
							</td>
						</tr>
						<tr>
							<td colspan="7">
								<html:radio property="agreementScope" styleId="allPartsScope" value="allParts" onclick="enableAllParts()" disabled="${disableScope}"></html:radio>
								<bean:message key="agreementDetail.label.allParts"/>
							</td>
							
						</tr>
						<tr>
							<td class="text_blue_bold align_left">
								<html:radio property="agreementScope" styleId="commodityScope" value="commodity" onclick="enableCommodity()" disabled="${disableScope}"></html:radio>
								<bean:message key="part.label.tableHeader.commodity" />:
							</td>
							<td colspan="6">
								<div id="commodityDiv">
									<html:select property="commodity">
										<html:option value="-1"><bean:message key="label.allOption" /></html:option>
										<html:options collection="commColl"
												  property="eesp02CommodityNumberK"
												  labelProperty="eesp02CommodityNameN" style="heigth=10"/>
									</html:select>
								</div>
							</td>
						</tr>
						<tr>
							<td class="text_blue_bold align_left" width="16%">
								<html:radio property="agreementScope" styleId="partScope" value="part" onclick="enablePart();" disabled="${disableScope}"></html:radio>
								<bean:message key="part.label" />:&nbsp;
							</td>
							<td class="text_blue_bold align_left" colspan="4" width="56%">
								<div id="partDiv"> 
									<html:select property="partClass" styleId="partClass" >
										<html:option value="-1"><bean:message key="label.selectOption" /></html:option>
										<html:options collection="partClassColl"
												  property="value"
												  labelProperty="label" style="heigth=10"/>
									</html:select>
									<html:text property="prefix" styleId="partPrefix" size="9" maxlength="10"/>&nbsp;					
									<html:text property="base" styleId="partBase" size="9" maxlength="10"/>&nbsp;
									<html:text property="suffix" styleId="partSuffix" size="9" maxlength="10"/>
									<html:button property="lookPart" onclick="searchNamePart('lookupedPart', 'partClass', 'partPrefix', 'partBase', 'partSuffix');" styleClass="button_small">...</html:button>
									<html:button property="findParts" onclick="findPartPopup('supplierClassH', 'supplierCodeH', 'partClass', 'partPrefix', 'partBase', 'partSuffix');" styleClass="button_small" style="width:20px;">?</html:button>				
								</div>
							</td>
							<td colspan="2" width="28%">
								<div style="display:inline;" id="lookupedPart" />	
							</td>
						</tr>
						<tr height="10px"/>
						<tr>
							<td class="text_blue_bold align_left" colspan="3" width="36%">
								<html:radio property="agreementClass" styleId="increaseRadio" value="I" onclick="enablePercent()"></html:radio>
								<div id="percentDiv" style="display: inline;">
								<bean:message key="agreementDetail.label.percentIncreaseGranted"/>:&nbsp;
								<html:text property="percentIncrease" size="7"></html:text>
								</div>
							</td>
							<td width="16%">
								<bean:message key="agreementDetail.label.effectiveDate"/>:
							</td>
							<td width="26%" colspan="2">
								<html:text property="effectiveDate" styleId="effectiveDate" size="10" maxlength="10"/><A name="effDateAnchor"> </A><html:button property="calendar" onclick="cal.select(document.AgreementDetailForm.effectiveDate,'effDateAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>
							</td>
							<td width="22%" >
								<bean:message key="agreementDetail.label.vehicleLine"/>:&nbsp;
								<html:select property="vehicleLine">:
										<html:option value="-1"><bean:message key="label.selectOption" /></html:option>
										<html:options collection="lineColl"
												  property="cas012VehicleCodeC"
												  labelProperty="cas012VehicleCodeC" style="heigth=10"/>
								</html:select>
							</td>
							
						</tr>
						<tr>
							<td colspan="3">
								<html:radio property="agreementClass" styleId="priceRadio" value="P" onclick="enableNewPrice()"></html:radio>
								<bean:message key="agreementDetail.label.newPrice"/>:&nbsp;
								<div id="newPriceDiv" style="display: inline;">
									<html:text property="newPrice" size="7"></html:text>
									<html:select property="currencyCode">
											<html:option value="-1"><bean:message key="label.selectOption" /></html:option>
											<html:options collection="currColl"
													  property="eesm01CurrencyCodeC"
													  labelProperty="eesm01CurrencyCodeC" style="heigth=10"/>
									</html:select>
								</div>								
							</td>
							<td class="text_blue_bold align_left">
								<bean:message key="agreementDetail.label.fullee&payPol"/>:
							</td>
							<td colspan="2">
								<html:text property="fulleeCode" styleId="fulleeCode" size="5"></html:text>
								<html:button property="findFulle" onclick="findFullEconomicPopup('fulleeCode');" styleClass="button_small" style="width:20px;">?</html:button>				
							</td>
							<td>
								<div style="display:inline;" id="fulleeName" />	
							</td>
						</tr>
					</table>
				</td>
				<td>
					<table style="width: 100px;" class="no_border">
						<tr>
							<td>
								<html:button property="sav" styleClass="button" onclick="createUpdateitem()"><bean:message key="label.createUpdate"/></html:button>
							</td>
						</tr>
						<tr>
							<td>
								<html:button property="canc" styleClass="button" onclick="cleanCreateFields()"><bean:message key="label.clean"/></html:button>
							</td>
						</tr>
					</table>
					
				</td>
			</tr>
		</table>
	</div>
	</div>	
	<br/>
	<table class="no_border" style="width: 850px;">
		<tr>
			<td colspan="2">
				<display-el:table 	class="table1" style="width: 850px;" cellpadding="5" uid="item"
									 pagesize="5" name="sessionScope.AgreementDetailForm.items" 
									excludedParams="*" requestURI="AgreementDetailActionPaginate.do" >
					<display-el:column title="${itemTitle}" style="width: 8%;" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right">
						<bean:write name="item" property="eesr04AgritmNumberK"/>
					</display-el:column>
					<display-el:column title="${vehicleLineTitle}" style="width: 15%;" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right">
						<logic:empty name="item" property="ncas012VehicleVw">*</logic:empty>
						<logic:notEmpty name="item" property="ncas012VehicleVw"><bean:write name="item" property="ncas012VehicleVw.cas012VehicleCodeC"/></logic:notEmpty>
					</display-el:column>
					<display-el:column title="${typeTitle}" style="width: 15%;" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right">
						<logic:equal name="item" property="eesr04AgritmTypeCodeC" value="A">*</logic:equal>
						<logic:equal name="item" property="eesr04AgritmTypeCodeC" value="C">Comm</logic:equal>
						<logic:equal name="item" property="eesr04AgritmTypeCodeC" value="P">Part</logic:equal>
					</display-el:column>
					<display-el:column title="${descriptionTitle}" style="width: 20%;" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right">
						<logic:equal name="item" property="eesr04AgritmTypeCodeC" value="A"><bean:message key="agreementDetail.label.allParts"/></logic:equal>
						<logic:equal name="item" property="eesr04AgritmTypeCodeC" value="C">
							<bean:write name="item" property="teesp02Commodity.eesp02CommodityNumberK"/>:
							<bean:write name="item" property="teesp02Commodity.eesp02CommodityNameN"/>
						</logic:equal>
						<logic:equal name="item" property="eesr04AgritmTypeCodeC" value="P">
							<bean:write name="item" property="teesp04Supply.teesp01Part.eesp01PartClassCodeC"/>
							<bean:write name="item" property="teesp04Supply.teesp01Part.eesp01PartPrefixCodeC"/>&minus;<bean:write name="item" property="teesp04Supply.teesp01Part.eesp01PartBaseCodeC"/>&minus;<bean:write name="item" property="teesp04Supply.teesp01Part.eesp01PartSuffixCodeC"/>
						</logic:equal>
					</display-el:column>
					<display-el:column title="${increaseTitle}" style="width: 8%;" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right">
						<logic:notEmpty name="item" property="eesr04AgritmIncrPercentP"><bean:write name="item" property="eesr04AgritmIncrPercentP"/></logic:notEmpty>
						<logic:empty name="item" property="eesr04AgritmIncrPercentP">-</logic:empty>
					</display-el:column>
					<display-el:column title="${priceTitle}" style="width: 9%;" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right">
						<logic:empty name="item" property="eesr04AgritmNewpriceAmounA">-</logic:empty>
						<logic:notEmpty name="item" property="eesr04AgritmNewpriceAmounA">
							<bean:write name="item" property="eesr04AgritmNewpriceAmounA"/>
						</logic:notEmpty>
					</display-el:column>
					<display-el:column title="${effDateTitle}" property="eesr04AgritmEffectiveDateY" decorator="ar.com.ford.it.fullEconomics.view.displaytag.DateDecorator"  style="width: 10%;"  class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right" />
					<display-el:column title="${registerTitle}" style="width: 12%;"  decorator="ar.com.ford.it.fullEconomics.view.displaytag.CostStructureItemColumnDecorator" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right" >
						<bean:write name="item" property="eesr04CreateUserC"/><br />
						<bean:write name="item" property="eesr04CreateS"/>
					</display-el:column>
					<display-el:column title="${actionsTitle}"  style="width: 10%;" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right">
							<html:image property="" alt="${edit}"
								onclick="editItem(${item_rowNum});" page="/images/edit.gif"
								style="width:20px" />&nbsp;
							<div style="cursor: pointer; display: inline;"><html:img alt="${delete}" onclick="deleteItem(${item_rowNum});" page="/images/erase.gif"
								style="width:20px" /></div>
					</display-el:column>
				</display-el:table>
			</td>		
		</tr>
		<tr>
			<td colspan="2" class="text_blue_bold align_left">
				<bean:message key="label.comments"/>
			</td>
		</tr>
		<tr>
			<td class="align_left">
				<html:textarea property="comments" rows="2" cols="95"></html:textarea>
			</td>
			<td>
				<html:button property="comm" styleClass="button" onclick="saveComments()"><bean:message key="label.save"/></html:button>
			</td>
		</tr>
	</table>
	<DIV ID="calDiv" STYLE="position:absolute;visibility:hidden;background-color:white;layer-background-color:white;"></DIV>
</html:form>
<script language="javascript">
	if(document.AgreementDetailForm.section.value != "edit"){ 
		enableDiv('partDiv',document.getElementById('partScope').checked,!document.getElementById('partScope').checked);
		enableDiv('commodityDiv',document.getElementById('commodityScope').checked,!document.getElementById('commodityScope').checked);
	}else{
		enableDiv('partDiv',false,!document.getElementById('partScope').checked);
		enableDiv('commodityDiv',false,!document.getElementById('commodityScope').checked);
	}
	if(document.getElementById('priceRadio').checked==false)
		enableDiv('newPriceDiv',false,true);
	if(document.getElementById('increaseRadio').checked==false)
		enableDiv('percentDiv',false,true);
</script>